package com.breezelin.freshmarket.app;

/**
 * Created by Breeze Lin
 * 18:09 2016/4/5
 * 1linyufeng1@gmail.com
 */

import android.os.Handler;
import android.os.Looper;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import com.umeng.analytics.MobclickAgent;

import cn.jpush.android.api.JPushInterface;

/**
 * 应用内所有Activity的父类
 */
public class BaseActivity extends AppCompatActivity {

	// TODO: 2016/4/5 定制

	/**
	 * 用于打印日志的标签
	 */
	@SuppressWarnings("unused")
	protected String TAG = BaseActivity.class.getSimpleName();

	/**
	 * 弹出提示
	 *
	 * @param content 提示内容
	 */
	protected void showToast(String content) {
		if (Looper.myLooper() != null) {
			Toast.makeText(this, content, Toast.LENGTH_SHORT).show();
		} else {
			final String finalContent = content;
			Handler handler = new Handler(Looper.getMainLooper());
			handler.post(new Runnable() {
				@Override
				public void run() {
					Toast.makeText(BaseActivity.this, finalContent, Toast.LENGTH_SHORT).show();
				}
			});
		}
	}

	/**
	 * 弹出提示
	 *
	 * @param contentRes 提示内容资源编号
	 */
	protected void showToast(int contentRes) {
		showToast(getString(contentRes));
	}

	@Override
	protected void onPause() {
		super.onPause();
		// 极光统计
		JPushInterface.onPause(this);
		// 友盟页面统计
		MobclickAgent.onPause(this);
	}

	@Override
	protected void onResume() {
		super.onResume();
		// 极光统计
		JPushInterface.onResume(this);
		// 友盟页面统计
		MobclickAgent.onResume(this);
	}
}
